#include "MyShellActionScope.h"
#include "MyShellException.h"

mysh::VariableInfo::VariableInfo(): 
    dimension(0), 
    data_type(mysh::WORD_TYPE::ILLEGAL_WORD), 
    size_of_every_demension(std::vector<std::size_t>())
{
}

mysh::VariableInfo::VariableInfo(
    const std::int32_t& dimension, 
    mysh::WORD_TYPE data_type, 
    const std::vector<std::size_t>& size_of_every_demension): 
    dimension(dimension), 
    data_type(data_type), 
    size_of_every_demension(size_of_every_demension)
{
}

mysh::VariableInfo::~VariableInfo()
{
}

mysh::MyShellActionScope::~MyShellActionScope()
{
    this->declared_variables.clear();
}

// 添加声明的变量
void mysh::MyShellActionScope::addDeclaredVariables(const std::shared_ptr<mysh::DeclareStatementNode>& declare_statement)
{
    for (auto identifier : declare_statement->identifiers)
    {
        if (this->declared_variables.count(identifier))
        {
            throw ExecutorException("\033[31m变量" + identifier + "重复声明\033[0m");
        }
        this->declared_variables[identifier] = mysh::VariableInfo(declare_statement->dimension, declare_statement->data_type, declare_statement->size_of_every_demension);
    }
}